
import { registerClass } from "../../../cfw/tools/class_decorator";
import BaseAd from "../../core/base/BaseAd";
/**
 * https://minigame.vivo.com.cn/documents/#/api/ad/interstitial-ad
 * 1031标准开始支持，低版本需做兼容处理。
 * 插屏广告实例不能复用，每次需要重新加载时要重新create
 */
@registerClass('VivoInsertAd')
export default class VivoInsertAd extends BaseAd {

    protected name: string = "VivoInsertAd"

    show(): void {
        if (this.ad) {
            this.ad.show();
        }
    }
    open() {
        this.create()
        this.show();
    }



    create() {
        this.destroy();
        console.log(' create insert ad ')
        if (!this.ad) {
            this.ad = this.sdk.createInterstitialAd({
                posId: this.adUnitID
            });
            this.ad.onLoad(this.getFunc(this.onLoad))
            this.ad.onError(this.getFunc(this.onError))
        } else {
            this.ad.load();
        }




    }


    destroy(): void {
        if (this.ad) {
            this.ad.offLoad(this.getFunc(this.onLoad))
            this.ad.offError(this.getFunc(this.onError))
            this.ad.destroy();
            this.ad = null;
        }
    }

}